<template>
    <div>
        <table>
            <tr>
                <td>登录名</td>
                <td><input type="text" v-model="data.name"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" v-model="data.pwd"></td>
            </tr>
            <tr>
                <td><input type="button" value="登录" @click="Login"></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const rount=useRouter()

const data=ref({
  "id": 1,
  "name": "",
  "pwd": ""
})

const Login=()=>{
    axios.get("https://localhost:7087/api/User/Login",{params:data.value}).then(res=>{
        if(res.data.id>0){
            localStorage.setItem("islogin","true");
            alert("登录成功")
            rount.push({path:'/ShowView'})
            return;
        }
        if(res.data.id==-1){
            alert("登录名不正确")
            return;
        }
        if(res.data.id==-2){
            alert("密码错误")
            return;
        }
    })
}

</script>

<style scoped>

</style>